/**
 * Created by Administrator on 2018/6/20.
 */
$CertusJsonAjax.ajax("queryBidProcessTrace",{
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
},function(res){
    $$scope.processCCBXTrace = res.data;
})
$CertusJsonAjax.ajax('bidBaseInfo', {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
}, function (res) {
    $$scope.file = {}
    $$scope.classfictionselect = [
        {name: '内部保密', value: "0"},
        {name: '内部公开', value: "1"},
        {name: '完全公开', value: "2"},
        {name: '请选择', value: "xxxx"}
    ];
    $$scope.file.classfiction = "xxxx"
    $$scope.rangeSelect = [
        {name: '请选择', value: "xxxx"},
        {name: '公司内部', value: "0"},
        {name: '公开信息', value: "1"}
    ]
    $$scope.file.range = "xxxx"
    $$scope.permissionSelect = [
        {name: '请选择', value: "xxxx"},
        {name: '总经理', value: "0"},
        {name: '总监', value: "1"},
        {name: '本部门', value: "2"}
    ]
    $$scope.file.permission = "xxxx"

    var picker2 = $('#datetime').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if(result && !angular.isUndefined(result)){
            $$scope.file.validity= result;
            $$scope.$apply();
        }
    })

    $$scope.bid = res.data;
    $$scope.bid.processInstanceId =  $CertusJsonAjax.getProInstanceId();
    $$scope.bid.stepInstanceId =  $CertusJsonAjax.getStepInstanceId();
})

$$scope.shutdown = function(){
    $CertusJsonAjax.ajax("bidshutdown",$$scope.bid,function(res){
        history.back();
    })
}

$$scope.formSubmitted = function(){
    $$scope.bid.nameOfPage = "交付方案";
    var form = new FormData();
    var file = document.getElementById("fileUploadId").files[0];
    form.append('file', file);
    if (file && file.size > 0) {
        form.append("classfiction", $$scope.file.classfiction);
        form.append("range", $$scope.file.range);
        form.append("permission", $$scope.file.permission);
        form.append("validity", $$scope.file.validity);
        $CertusFormAjax.upload("processUploadFile", form, function (res) {
            $$scope.bid.uploadFilePath = res.data;
            $$scope.bid.pathFrom = "selbidB";
            $CertusJsonAjax.ajax("bidSubmitalter", $$scope.bid, function (res) {
                toLoadHtml(14)
            })
        })
    } else {
        layer.msg("请上传文件");
    }
}

//文件上传统一字段
function showfile() {
    $(".hidefile").show();
}

function hidefile() {
    $(".hidefile").hide();
}

$$scope.relatedUser = function(){
    var regex = /[0-9a-zA-Z]*/g;
    var numList =  $$scope.bid.principalName.match(regex);
    $CertusFormAjax.ajax("confirmUserId",{name: numList.join().replace(",","")},function(res){
        if(res.data != "fail"){
            $$scope.bid.specifiedMan = res.data;
        }
    })

    if($$scope.bid.principalName != ""){
        $CertusFormAjax.ajax("relatedUser",{name:$$scope.bid.principalName}, function (res) {
            $$scope.userSelect = res.data;
        });
    }
}